package com.yp.demo.web;

import com.yp.demo.entity.User;
import com.yp.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private UserRepository userRepository;

    @GetMapping("/user")
    public Map<String, Object> user(Principal puser) {
        User user = userRepository.findByPhone(puser.getName());
        Map<String, Object> json = new HashMap<>();
        json.put("user", user);
        json.put("detail",user.getDetail());
        json.put("created_at", user.getCreatedAt());
        json.put("updated_at", user.getUpdatedAt());
        return json;
    }
}
